<?php 
include_once "common/basic.php";
$vkey = $_GET[vkey];
if($vkey){
	$arr_vkey = explode("_", $vkey);
	if(count($arr_vkey)!=2){
		$func->error("e12062201","无效的重置密码确认链接");
	}
	$user = $func->getUserById($arr_vkey[0]);
	if(!$user){
		$func->error("e12062202","无效的重置密码确认链接");
	}
	if($func->v_resetpwd($arr_vkey[0],$arr_vkey[1])==0){
		$func->error("e12062203","无效的重置密码确认链接");
	}
	if($_POST[reset]){
		if(!$_POST[pwd]){
			$err_pwd = "密码不能为空";
		}elseif($func->v_password($_POST[pwd])!==true){
			$err_pwd = $func->v_password($_POST[pwd]);
		}elseif(!$_POST[pwd2]){
			$err_pwd2 = "密码不能为空";
		}elseif($_POST[pwd]!=$_POST[pwd2]){
			$err_pwd = "两次输入的密码不一致";
		}else{
			if($func->user_set_password($user[uid],$_POST[pwd])){
				$pwdchanged = $func->resetpwd_vkey_delete($user[uid]);
			}
		}
	}
}elseif(isset($_GET[email])){
	if($_GET[email]){
		$email = $_GET['email'];
		if(!util::validateEmail($email)){
			$err = "邮箱格式不正确！";
		}else{
			$user = $func->getUserByEmail($email);
			if($user){
				$vkey = $func->resetpwd_vkey_create($user[uid]);
				if($vkey){
					$sendmail = $func->mail_resetpwd($user,$vkey,$config[smtp],$config[weburl],$config[webname]);
					if(!$sendmail){
						$func->error("e12062204","发送邮件失败，请稍后再试！");
					}
				}
			}else{
				$err = "这个邮箱地址没有注册过！";
			}
		}
	}else{
		$err = "请填写邮箱地址";
	}
}
$tl->set_file("resetpwd");
$tl->p();
?>